Ext.namespace('Ext.ux.grid');


Ext.ux.grid.RESTGrid = Ext.extend(Ext.grid.EditorGridPanel, {
	/*
	 * Search Text
	 */
	// Search Texts
 	  searchText : "Buscar"
	, searchTipText : "Buscar en la lista de items"
	, selectAllText : "Todos"

	, initComponent:function(config) {
		this.resourceURL = this.resourceURL;

		this.ds = new Ext.data.GroupingStore({
			proxy : new Ext.data.HttpProxy({url : this.resourceURL, method : 'get'})
			, reader : this.reader
			, sortInfo : { field : 'name', direction : "ASC" }
		});
		this.sm = new Ext.grid.RowSelectionModel({ singleSelect : true });

		// Top Bar
		this.tbar = ['->'];

		// Plugins
		this.plugins = [new Ext.ux.grid.Search({
			  mode : 'local'
			, iconCls : false
			, dateFormat : 'm/d/Y'
			, readonlyIndexes : []
			, disableIndexes : []
			, minLength : 2
			, position : 'top'
			, width: 200
			, searchText : this.searchText
			, searchTipText : this.searchTipText
			, selectAllText : this.selectAllText
		}), this.rowActions];
		Ext.ux.grid.RESTGrid.superclass.initComponent.apply(this, config);
	} // eo function initComponent

	, addRecord : function() {
		var store = this.store;
		if(store.recordType) {
			var rec = new store.recordType({newRecord:true});
			rec.fields.each(function(f) {
				rec.data[f.name] = f.defaultValue || null;
			});
			rec.commit();
			store.insert(0, rec);
			return rec;
		}
		return false;
	}

	, onRender : function() {
		// call parent
		Ext.ux.grid.RESTGrid.superclass.onRender.apply(this, arguments);

		// load store
		this.store.load({
			params : {
				start : 0,
				limit : 10
			}
		});

	} // eo function onRender
});